package main

import (
	"fmt"
	"github.com/elliotchance/pie/v2"
)

func main() {

	type User struct {
		Name string
		Age  int
	}

	users := []User{
		{
			Name: "Tom",
			Age:  10,
		},
		{
			Name: "Jerry",
			Age:  20,
		},
	}

	underAgeUsers1 := pie.Of(users).Filter(func(user User) bool {
		return user.Age > 18
	})

	var underAgeUsers2 []User
	for _, user := range users {
		if user.Age > 18 {
			underAgeUsers2 = append(underAgeUsers2, user)
		}
	}

	fmt.Println(underAgeUsers1)
	fmt.Println(underAgeUsers2)

	ascAgeUsers := pie.Of(users).SortUsing(func(a, b User) bool {
		return a.Age < b.Age
	})

	fmt.Println(ascAgeUsers)
}
